package com.huangwenshuo.futurestarschoolmanagement.controller;


import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.ActivityDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.WorkDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.enums.RequestStateEnum;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.Result;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.WorksVo;
import com.huangwenshuo.futurestarschoolmanagement.service.WorksService;
import com.huangwenshuo.futurestarschoolmanagement.utils.ResUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangwenshuo
 * @since 2021-03-06
 */
@RestController
@RequestMapping("/works")
public class WorksController {

    @Autowired
    private WorksService worksService;
    @PostMapping("/addWork")
    public Result addWork(@RequestBody WorkDto.AddWork addWork){
        try {
            worksService.addWork(addWork);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"添加成功");
    }

    @PostMapping("/upaWork")
    public Result upaWork(@RequestBody WorkDto.AddWork addWork){
        try {
            worksService.upaWork(addWork);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"添加成功");
    }

    @GetMapping("/getMyWorks")
    public Result getMyWorks(WorkDto.GetWork getWork){
        Map<String,Object> res = new HashMap<>();
        try {
            res= worksService.getMyWorks(getWork);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),res,"查询成功");
    }

    @GetMapping("/getShowMyWorks")
    public Result getShowMyWorks(Integer uid){
        List<WorksVo> worksVos= null;
        try {
            worksVos= worksService.getShowMyWorks(uid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),worksVos,"查询成功");
    }

    @GetMapping("/updateShow")
    public Result updateShow(Integer uid,Integer aid,Integer show){
        try {
           worksService.updateShow(uid,aid,show);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"查询成功");
    }


}

